#!/usr/bin/env python
#-*- coding:utf-8 -*-
'''
__author-default__ = 'Pup--->>WX_l599p22'
__cttime-default__ = '20170721'
'''

from flask_script import Manager
from app import app
import sqlite3
from models import User

manager = Manager(app)


@manager.command
def hello():
	print 'hello world!'

@manager.option('-m','--msg',dest='msg_val',default='world')
def hello_world(msg_val):
	print 'hello '+msg_val

@manager.command
def init_db():
	sql = 'create table user (id int,name text)'
	conn = sqlite3.connect('test.db')
	cur =conn.cursor()
	cur.execute(sql)
	conn.commit()
	cur.close()
	conn.close()

@manager.command
def save():
	user = User(1,'admin')
	user.save()

@manager.command
def query_all():
	users = User.query()
	for user in users:
		print user



if __name__=='__main__':
	manager.run()